#ifndef __USER_MGR_H__
#define __USER_MGR_H__
#include <mutex>
#include <map>
#include <memory>
#include "log.h"
#include "nfapi.h"

using namespace nfapi;
enum PROXY_STATE
{
    PS_NONE,
    PS_REQUEST,
    PS_CONNECT,
    PS_CONNECT_SOCKS4,
    PS_CONNECTED_UDP,
    PS_CONNECTED,
    PS_ERROR,
    PS_CLOSED
};
class DestAddr
{
public:
    DestAddr(PNF_TCP_CONN_INFO pConnInfo)
    {
        std::memcpy((void *)&connInfo, (char *)pConnInfo, NF_MAX_ADDRESS_LENGTH);
    }
    unsigned int GetIP()
    {
        if (connInfo.ip_family == AF_INET)
        {
            return ((struct sockaddr_in *)&connInfo.remoteAddress[0])->sin_addr.s_addr;
        }
        else
        {
            return *((unsigned int *)&((struct sockaddr_in6 *)&connInfo.remoteAddress[0])->sin6_addr.u.Word[0]);
        }
    }
    unsigned short GetPort()
    {
        if (connInfo.ip_family == AF_INET)
        {
            return ((struct sockaddr_in *)&connInfo.remoteAddress[0])->sin_port;
        }
        else
        {
            return (((struct sockaddr_in6 *)&connInfo.remoteAddress[0])->sin6_port);
        }
    }
    ~DestAddr() {}
    NF_TCP_CONN_INFO connInfo = {0};
};
class AuthInfo
{
public:
    AuthInfo(const char *ip, int port,
             const char *name, const char *pwd)
    {
        sIP = ip;
        sName = name;
        iPort = port;
        sPassWord = pwd;
    }
    ~AuthInfo() {}
    std::string sIP;
    std::string sName;
    std::string sPassWord;
    int iPort;
};
#define TAUTH std::shared_ptr<AuthInfo>
#define TADDR std::shared_ptr<DestAddr>

class UserMgr
{
public:
    UserMgr();
    ~UserMgr();
    void AddProxyUser(int pid, TAUTH au);
    void DellProxyUser(int pid);
    TAUTH QueryProxyUser(int pid);

private:
    std::mutex m_Proxylock;
    std::map<int, TAUTH> m_ProxyList;
};
#endif // !__USER_MGR_H__
